<?php
    class Subtopik_con extends CI_Controller{
        function __construct() {
            parent::__construct();
        }
        function index(){

        }
        function isi_topik($id){
            $query = $this->db->get_where('topik_silabus',array('ID_TOPIK'=>$id));
            $row = $query->row();
            $content['ID_TOPIK']=$row->ID_TOPIK;
            $content['JUDUL_TOPIK']=$row->JUDUL_TOPIK;
            $this->db->order_by('NO_URUT','asc');
            $query = $this->db->get_where('isi_topik',array('ID_TOPIK'=>$id));
            if($query->num_rows()>0){
                $this->load->library('table');
                $this->table->set_template(array('table_open' => '<table border="1" cellpadding="4" cellspacing="3">'));
                $this->table->set_heading('NO URUT', 'SUBTOPIK','AKSI');
                foreach ($query->result() as $entry) {
                    $this->table->add_row($entry->NO_URUT, $entry->SUBTOPIK,anchor(base_url().'admin/subtopik_con/delete_subtopik/'.$entry->ID_TOPIK.'/'.$entry->ID_SUBTOPIK,'DELETE'));
                }
                $content['isi']=$this->table->generate();
            }else{
                $content['isi']="Belum ada subtopik yang ditambahkan";
            }
            $data['title']='Isi Topik '.$row->JUDUL_TOPIK;
            $this->load->view('admin/admin_header_view',$data);
            $this->load->view('admin/topik_isi_view',$content);
            $this->load->view('footer_view');
        }
        function insert_isi(){
            $subtopik = $this->input->post('SUBTOPIK');
            $urutan = $this->input->post('NO_URUT');
            $id = $this->input->post('ID_TOPIK');
            if($subtopik!=''&&$urutan!=''){
                $this->db->insert('isi_topik',$_POST);
                redirect(base_url() . 'admin/subtopik_con/isi_topik/'.$id);
            }else{
                echo 'Harap isi judul ';
                echo '<a href="javascript:back()">Kembali</a>';
            }
        }
        function delete_subtopik($id_topik,$id_subtopik){
            $this->db->delete('isi_topik',array('ID_TOPIK'=>$id_topik,'ID_SUBTOPIK'=>$id_subtopik));
            redirect(base_url() . 'admin/subtopik_con/isi_topik/'.$id_topik);
        }
    }
?>
